package com.thingple.usb;

import android.view.View;

import java.util.Calendar;

public class LimitedClick implements View.OnClickListener {

    private final View.OnClickListener listener;
    private final long limit;
    private long lastClick = 0;

    public LimitedClick(long limit, View.OnClickListener listener) {
        this.listener = listener;
        this.limit = limit;
    }
    @Override
    public void onClick(View v) {
        long curTime = Calendar.getInstance().getTimeInMillis();
        if (curTime - lastClick > limit) {
            lastClick = curTime;
            if(listener != null){
                listener.onClick(v);
            }
        }
    }
}
